﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="DisplayReview.aspx.cs" Inherits="CodeDemon.Views.Review.DisplayReview" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

<%
    var r = (from reviews in ViewData.Model.DAO.GetReviewsById(ViewData.Model.CurrentReviewID) select reviews).FirstOrDefault();
     %>
     
     
<div class="reviewSummary">

    <h1>CR-<%=r.ReviewID.ToString() %> <%=r.Title.ToString() %></h1>
<%
    var reviewers = from partlist in ViewData.Model.DAO.GetReviewParticipantsByReviewID(ViewData.Model.CurrentReviewID) where partlist.ParticipantIsReviewer == true select partlist;
    var cc = from partlist in ViewData.Model.DAO.GetReviewParticipantsByReviewID(ViewData.Model.CurrentReviewID) where partlist.ParticipantIsReviewer == false select partlist;
    var owner = (from user in ViewData.Model.DAO.GetUserByUserID(r.ReviewOwnerID) select user).FirstOrDefault();
    var q = from files in ViewData.Model.DAO.GetReviewFilesByReviewId(ViewData.Model.CurrentReviewID) orderby files.EndRevision select files;
    var count = (from files in ViewData.Model.DAO.GetReviewFilesByReviewId(ViewData.Model.CurrentReviewID) select files).Count();
    int waitingOnReviews = 0;
    int totalReviewers = 0;
    int totalParticpants = 0;
    int totalApprovals = 0;
    bool currentUserIsRev = false;
    bool currentUserIsPart = false;
%>

<span title="Review Owner" class="author"><%= owner.RealName %></span>

<% foreach (var u in reviewers)
   {
       if (u.ReviewUserID == ViewData.Model.CurrentReviewUserID)
       {
           if (u.ParticipantIsReviewer == true)
           {
               currentUserIsRev = true;
           }
           currentUserIsPart = true;
       }
       totalReviewers++;
       totalParticpants++;
       if (u.IsApprovalStatus == true) {
       totalApprovals++;
           
           %>
       <span title="Participant Has Approved" class="complete"><%= u.RealName%></span>,
   <% }

       if (u.IsFinishedStatus == true && u.IsApprovalStatus != true)
       {
           %>
        <span title="Participant Has Rejected" class="failed"><%= u.RealName%></span>, 
        <%
       }

       if (u.IsApprovalStatus == false && u.IsFinishedStatus == false)
       {
           waitingOnReviews++;
           if (u.VisitTimeStamp != null) {
           %>
            <span title="Incomplete Approval, Has Visited" class="partial"><%= u.RealName%></span>,
            <% } else { %>
            <span title="Incomplete Approval, Has Not Visited" class="incomplete"><%= u.RealName%></span>,
            
<%          }
       }
       } %>    
<% foreach (var x in cc)
   {
       totalReviewers++;
       totalParticpants++;
       %>
       <span title="Auxillery Participant" class="cc"><%= x.RealName%></span>
   <% } %>  
<div class="reviewMessageBlock">
    <span class="reviewMessage">This review was created for <a href="<%=ConfigurationManager.AppSettings["DefectSystem_LookupURL"] %><%=r.DefectNumber %>">Defect <%= r.DefectNumber %></a>.</span>
    <hr style="width:200px; text-align: left; margin: 5px auto 5px 5px;"/>
    <span title="Review Owner" class="author"><%= owner.RealName %></span> created on <%=r.ReviewCreatedTimeStamp %>
    <hr style="width:200px; text-align: left; margin: 5px auto 5px 5px;"/>
     <span class="reviewMessage"><%= r.Description %></span>
</div>

<div class="statusMessageBlock">
    <span class="statusMessage">Review is Currently in status <span class="reviewStatus <%=r.StatusName.ToString() %>Status"><%=r.StatusName.ToString() %></span></span>
    
<hr style="width:200px; text-align: left; margin: 5px auto 5px 5px;"/>
    <span class="statusMessageStatistics">
        This review has <%= totalParticpants %> total particpants, is waiting on <%=waitingOnReviews %> approvals, has gathered <%=totalApprovals%> approvals and contains <%=count %> files.
    </span>
</div>

<div class="reviewOperationsBlock">
        <%if( currentUserIsRev == true ) { %>
            <span class="reviewOperation"><a href="#" class="ex4trigger">Approve or Reject</a></span>
        <% } %>

    <span class="reviewOperation"><a href="#" class="ex2trigger" id="newReviewComment">Add Comment</a></span>
    <%if (ViewData.Model.CurrentReviewUserID == r.ReviewOwnerID)
      { %>
    <span class="reviewOperation"><a href="#" class="ex3trigger">Edit Review</a></span>
    <% }
      else
      { %>
      <% if( !currentUserIsRev && !currentUserIsPart ) { %>
           <span class="reviewOperation"><a href="#" class="ex_join_as_rev_trigger">Join As Reviewer</a></span>
            <span class="reviewOperation"><a href="#" class="ex_join_as_cc_trigger">Join As Participant</a></span>
        <% } %>
    <% } %>
    <span class="reviewOperation"><a href="#" id="showReviewLog">View Review Log</a><a href="#" id="hideReviewLog">Hide Review Log</a></span>
    </div>
</div>

<div class="reviewLogBlock" id="reviewLogBlock"><div style=" text-align: center; margin: 100px 0 0 60px ; width:18em;"><img src="/CodeDemon/Content/spinner-big.gif" /><br/><br/><span class="loading">Loading...</span></div></div>
<div class="jqmWindow" id="ex2"><div style=" text-align: center; margin: 100px 0 0 60px ; width:18em;"><img src="/CodeDemon/Content/spinner-big.gif" /><br/><br/><span class="loading">Loading...</span></div></div>
<div class="jqmWindow" id="ex3"><div style=" text-align: center; margin: 100px 0 0 60px ; width:18em;"><img src="/CodeDemon/Content/spinner-big.gif" /><br/><br/><span class="loading">Loading...</span></div></div>
<div class="jqmWindow" id="ex4"><div style=" text-align: center; margin: 100px 0 0 60px ; width:18em;"><img src="/CodeDemon/Content/spinner-big.gif" /><br/><br/><span class="loading">Loading...</span></div></div>
<div class="jqmWindow" id="ex_join_as_rev"><div style=" text-align: center; margin: 100px 0 0 60px ; width:18em;"><img src="/CodeDemon/Content/spinner-big.gif" /><br/><br/><span class="loading">Loading...</span></div></div>
<div class="jqmWindow" id="ex_join_as_cc"><div style=" text-align: center; margin: 100px 0 0 60px ; width:18em;"><img src="/CodeDemon/Content/spinner-big.gif" /><br/><br/><span class="loading">Loading...</span></div></div>

<div class="reviewHeader">Review Comments</div>
<div class="reviewComments">
    <script type="text/javascript">
        $().ready(function() {
            ReadyReview('<%= ViewData.Model.CurrentReviewID %>');
            getComments('<%= ViewData.Model.CurrentReviewID %>');    
        }); 
    </script>
    <span id="commentContainer"></span>
</div>

<br />
<div class="reviewHeader">Review Contents</div>
<br />
<%

    foreach (var v in q)
    {
        if (v.IsBinary == false)
        {
        %>
        
        <div>
            <a style="cursor:pointer;" id="show<%= v.ReviewFileID %>"><img id="arrow<%= v.ReviewFileID %>" src="/CodeDemon/Content/arrow_closed.gif" style="cursor:pointer;border:none 0px" alt="Show" />&nbsp;&nbsp;<%=v.FilePath%></a>
            <a style="cursor:pointer;" id="hide<%= v.ReviewFileID %>"><img id="arrow2<%= v.ReviewFileID %>" src="/CodeDemon/Content/arrow_open.gif" style="cursor:pointer;border:none 0px" alt="Hide" />&nbsp;&nbsp;<%=v.FilePath%></a> <% } else{ %><div><img src="/CodeDemon/Content/icon_binary.gif" style="border:none 0px" alt="Binary File" />&nbsp;&nbsp;<%=v.FilePath%>&nbsp;&nbsp;<% } %><img  style="cursor:pointer;" alt="Show Commit Log" id="logicon<%= v.ReviewFileID %>" src="/CodeDemon/Content/icn_annotation.gif" style="border:none 0px" />
             <img alt="Hide Commit Log" style="cursor:pointer;" id="hidelogicon<%= v.ReviewFileID %>" src="/CodeDemon/Content/icn_annotation.gif" style="border:none 0px" />

             &nbsp; <a href="<%=ConfigurationManager.AppSettings["FishEyeRepoLookupURL"] %><%= v.RepositoryKey %><%=v.FilePath %>#r<%=v.EndRevision %>"><img alt="FishEye History" src="/CodeDemon/Content/icn_history.gif" style="border:none 0px" /></a>
                &nbsp;<a href="<%=ConfigurationManager.AppSettings["FishEyeRepoLookupURL"] %><%= v.RepositoryKey %><%=v.FilePath %>?r=<%=v.EndRevision %>"><img alt="FishEye Revision" src="/CodeDemon/Content/new_in_tab.gif" style="border:none 0px" /></a>
                &nbsp;<a onclick="this.target = '_blank';" href="<%=ConfigurationManager.AppSettings["NewDefectURL"] %>?product=SMARTworks%206.0&amp;version=unspecified&amp;rep_platform=---&amp;op_sys=Windows&amp;priority=P4&amp;bug_severity=normal&amp;target_milestone=---&amp;bug_status=NEW&amp;assigned_to=&amp;qa_contact=&amp;bug_file_loc=http%3A%2F%2F&amp;short_desc=Problem%20with%20<%=v.FilePath %>&amp;comment=&amp;keywords=&amp;status_whiteboard=&amp;dependson=&amp;blocked=<%= v.FileDefectNumber %>,<%= v.DefectNumber %>&amp;form_name=enter_bug"><img alt="Enter Bug" src="/CodeDemon/Content/bugzilla16.png" style="border:none 0px" /></a>&nbsp;[<a class="perma" href="/CodeDemon/Review/DisplayReviewFileSingle?reviewFileID=<%= v.ReviewFileID %>">#Link</a>]
                &nbsp; <a href="<%=ConfigurationManager.AppSettings["FishEyeChangeLogURL"] %><%=v.EndRevision %>"><%=v.StartRevision %>-<%=v.EndRevision %></a> 
               <% if (v.ChangeAction == "M ")
                   { %>
                    <span class="filestatus">Modified</span>
                <% } %>
                <% if (v.ChangeAction == "D ")
                   { %>
                    <span class="filestatus">Deleted</span>
                <% } %>
                <% if (v.ChangeAction == "A ")
                   { %>
                    <span class="filestatus">Added</span>
                <% } %>  
        </div>
        <div id="msg<%= v.ReviewFileID %>" class="fileLogMsg" style="display:none;">
            <span class="line">By <%= v.Author %> on <%= v.ChangeDate %></span>
            <pre class="line"><%= LinkLogMessage(v.LogMessage) %></pre></div> <% if (v.IsBinary == false)
                                                                                 { %>
        <div id="div<%= v.ReviewFileID %>"><img src="/CodeDemon/Content/spinner.gif" alt="Loading" />Loading Diff...</div>
        <script type="text/javascript">

             $(document).ready(function() {
                ReadyReviewFile( '<%= v.ReviewFileID %>');
             
             });
            </script>
        <%
    }
    else
      {
      %>
       <script type="text/javascript">
        ReadyBinaryFile( '<%= v.ReviewFileID %>' );
       </script>
       <%
       }
    }
        %>
     
</asp:Content>
